package com.ruoyi.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.mapper.AdvMembersaddrMapper;
import com.ruoyi.domain.AdvMembersaddr;
import com.ruoyi.service.IAdvMembersaddrService;
import org.springframework.transaction.annotation.Transactional;

/**
 * Service业务层处理
 *
 * @author ruoyi
 * @date 2024-06-04
 */
@Service
public class AdvMembersaddrServiceImpl implements IAdvMembersaddrService
{
    @Autowired
    private AdvMembersaddrMapper advMembersaddrMapper;

    /**
     * 查询
     *
     * @param advMembersaddrId 主键
     * @return
     */
    @Override
    public AdvMembersaddr selectAdvMembersaddrByAdvMembersaddrId(Long advMembersaddrId)
    {
        return advMembersaddrMapper.selectAdvMembersaddrByAdvMembersaddrId(advMembersaddrId);
    }

    /**
     * 查询列表
     *
     * @param advMembersaddr
     * @return
     */
    @Override
    public List<AdvMembersaddr> selectAdvMembersaddrList(AdvMembersaddr advMembersaddr)
    {
        return advMembersaddrMapper.selectAdvMembersaddrList(advMembersaddr);
    }

    /**
     * 新增
     *
     * @param advMembersaddr
     * @return 结果
     */
    @Override
    @Transactional
    public int insertAdvMembersaddr(AdvMembersaddr advMembersaddr)
    {
        // 新增的时候, 先判断当前的提交是否为默认用户
        if(advMembersaddr.getRecvDefault().equals("1")) {
            // 如果是默认用户就要先把其他的默认用户去掉
            advMembersaddrMapper.removeDefault(advMembersaddr.getAdvMembersId());
        }
        return advMembersaddrMapper.insertAdvMembersaddr(advMembersaddr);
    }

    /**
     * 修改
     *
     * @param advMembersaddr
     * @return 结果
     */
    @Override
    @Transactional
    public int updateAdvMembersaddr(AdvMembersaddr advMembersaddr)
    {
        if(advMembersaddr.getRecvDefault().equals("1")) {
            // 如果是默认用户就要先把其他的默认用户去掉
            advMembersaddrMapper.removeDefault(advMembersaddr.getAdvMembersId());
        }
        return advMembersaddrMapper.updateAdvMembersaddr(advMembersaddr);
    }

    /**
     * 批量删除
     *
     * @param advMembersaddrIds 需要删除的主键
     * @return 结果
     */
    @Override
    public int deleteAdvMembersaddrByAdvMembersaddrIds(Long[] advMembersaddrIds)
    {
        return advMembersaddrMapper.deleteAdvMembersaddrByAdvMembersaddrIds(advMembersaddrIds);
    }

    /**
     * 删除信息
     *
     * @param advMembersaddrId 主键
     * @return 结果
     */
    @Override
    public int deleteAdvMembersaddrByAdvMembersaddrId(Long advMembersaddrId)
    {
        return advMembersaddrMapper.deleteAdvMembersaddrByAdvMembersaddrId(advMembersaddrId);
    }
}
